package com.qymerge.manage.core.third.wechat.dto.twocode;

import lombok.Data;

import java.io.Serializable;

/**
 * Desc 创建二维码ticket - 请求
 * User licong
 * Date 2016/6/20
 * Time 10:58
 */
@Data
public class TwoCodeRequestDTO implements Serializable{

    private long expire_seconds;//该二维码有效时间，以秒为单位。 最大不超过2592000（即30天），此字段如果不填，则默认有效期为30秒。
    private String action_name; //二维码类型，QR_SCENE 为临时,QR_LIMIT_SCENE 为永久,QR_LIMIT_STR_SCENE为永久的字符串参数值
    private long scene_id;      //场景值ID，临时二维码时为32位非0整型，永久二维码时最大值为100000（目前参数只支持1--100000）

    public TwoCodeRequestDTO() {}

    public TwoCodeRequestDTO(String action_name, long expire_seconds, long scene_id) {
        this.action_name = action_name;
        this.expire_seconds = expire_seconds;
        this.scene_id = scene_id;
    }

    /**
     * 请求数据
     * @return
     */
    public String requestJson(){
        //临时：{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}
        //永久：{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
        String exprice_infp = "";
        if (expire_seconds > 0 && expire_seconds <= 2592000){
            exprice_infp = "\"expire_seconds\": " + expire_seconds + ",";
        }
        //场景值ID，临时二维码时为32位非0整型，永久二维码时最大值为100000（目前参数只支持1--100000）
        if (action_name.equals("QR_LIMIT_SCENE") && scene_id > 100000){
            System.out.println("[创建永久二维码ticket] 场景值ID超过最大值 100000");
        }
        String json = "" +
                "{" +
                    exprice_infp +
                    "\"action_name\": \"" + action_name + "\"," +
                    "\"action_info\": {" +
                        "\"scene\": {" +
                            "\"scene_id\": " + scene_id + "" +
                        "}" +
                    "}" +
                "}";
        return json;
    }

}
